//
//  AboutViewController.m
//  Liuhe
//
//  Created by zr on 2018/8/7.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "AboutViewController.h"
#import "HotModel.h"
#import "HotOneTableViewCell.h"
#import "HotTwoTableViewCell.h"
#import "HotHeader.h"

@interface AboutViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, weak)UITableView * tableView;
@property (nonatomic, strong)NSArray <HotModel *> * hotModelArr;

@end

@implementation AboutViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = ColorWithRGB(0xF2F2F2);
    
    [HotModel hotModelWithSucess:^(NSArray<HotModel *> *array) {
        
        self.hotModelArr = array;
    } error:^{
        
    }];
    
    [self setupNav];
    [self setupUI];
    
}

- (void)setHotModelArr:(NSArray<HotModel *> *)hotModelArr{
    
    _hotModelArr = hotModelArr;
    
    [self.tableView reloadData];
}


- (void)setupNav{
    
    self.title = @"今日热点";
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(0, 0, 12 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"1返回"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
    
}

- (void)backToView{
    
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)setupUI{
    
    UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(18 * SCREENH6, 0, SCREEN_WIDTH - 36 * SCREENH6, SCREENH_HEIGHT - 64) style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = [UIColor whiteColor];
    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    
    
    self.tableView = tableView;
    
    [self.tableView registerClass:[HotOneTableViewCell class] forCellReuseIdentifier:@"HomeOneCell"];
    [self.tableView registerClass:[HotTwoTableViewCell class] forCellReuseIdentifier:@"HomeTwoCell"];
    [self.tableView registerClass:[HotHeader class] forHeaderFooterViewReuseIdentifier:@"HotHeader"];
    
    [self.view addSubview:self.tableView];
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    int count = (int )self.hotModelArr.count / 3;
    
    return count;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return self.hotModelArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  
    
    if (indexPath.row == 0) {
        
        HotOneTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeOneCell" forIndexPath:indexPath];
        
        cell.model = self.hotModelArr[indexPath.row];
        
        return cell;
    }else{
        
        HotTwoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeTwoCell" forIndexPath:indexPath];
        
        cell.model = self.hotModelArr[indexPath.row];
        
        return cell;
    }
    
    
}



- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return 30* SCREENH6;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    HotHeader *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"HotHeader"];

    return header;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 0) {

        return 150 * SCREENH6;
    }else{


        return 90 * SCREENH6;
    }

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
